package datautils;

/*import com.romaremez.testuser.src.userdata.User;
import com.romaremez.testuser.src.userdata.UserSession; */
import org.apache.log4j.Logger;
import userdata.User;
import userdata.UserSession;

import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Сохраняет базу пользователей и сессий в файл
 */
public class DataSaver {
    private Map<User, List<UserSession>> userTable;
    private static final Logger logger = Logger.getLogger(DataSaver.class);

    public DataSaver(Map<User, List<UserSession>> userTable) {
        this.userTable = userTable;
    }

    public static void main(String[] args) {
        DataSaver dataSaver = new DataSaver(new HashMap<User, List<UserSession>>());
        dataSaver.saveDB();
    }

    public void saveDB() {
        File file = new File("DB.txt");
        try (ObjectOutputStream writer = new ObjectOutputStream(new FileOutputStream(file))) {
            writer.writeObject(userTable);
        } catch (IOException e) {
            logger.error("Can't save item " + e.getMessage());// todo handle exception
        }
    }
}
